package com.huangj.fragments;

import android.view.View;
import android.widget.ListView;

import com.huangj.adapter.TravelLvAdapter;
import com.huangj.entity.TravelEntity;
import com.huangj.huangjlibrary.base.BaseFragment;
import com.huangj.huangjlibrary.util.DownUtil;
import com.huangj.pro2_h2pop.R;
import com.huangj.util.Constant;
import com.huangj.util.JsonUtil;

import java.util.List;

import butterknife.BindView;

public class TravelsFragment extends BaseFragment implements DownUtil.OnDownListener {

    private TravelLvAdapter travelLvAdapter;
    @BindView(R.id.lv_travel)
    ListView lv_travel;

    @Override
    public int getContentId() {
        return R.layout.fragment_travels;
    }

    @Override
    protected void loadDatas() {
      new DownUtil().setOnDownListener(this).downJSON(Constant.URL_LIST);
    }

    @Override
    protected void init(View view) {
        travelLvAdapter = new TravelLvAdapter(getActivity());
        lv_travel.setAdapter(travelLvAdapter);
    }

    /**
     * 解析JSON；
     */
    @Override
    public Object paresJson(String json) {
        if (json!=null){
            return JsonUtil.getTravelEntityJson(json);
        }
        return null;
    }
    @Override
    public void downSucc(Object object) {

        List<TravelEntity> datas = (List<TravelEntity>) object;
        travelLvAdapter.setDatas(datas);
//        Log.d("print", "traveDATAS "+object.toString());
    }
}
